Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to have remoteTextTracks automatically 'garbage-collected' when sources change #3736

Merged
merged 7 commits into from
Nov 9, 2016

Conversation

imbcmdth
Copy link
Member

@imbcmdth imbcmdth commented Nov 3, 2016

Description

Right now "remoteTextTracks" persist between source changes and must be removed manually by the user. This is problematic in many cases. It means plugins that change sources, such as the playlist API or videojs-contrib-ads, have to be extremely careful about changes the source and take care to cleanup remoteTextTracks.

We do this because the Video.js API aligns very closely with the media element's native API. I propose that we could be doing more to iron-out the rough patches in the native API. In my opinion, the fact that previous changes to the media-element (adding text track elements) may change the behavior of a source is one of those rough patches.

Specific Changes proposed

Tech#addRemoteTextTrack now accepts a second parameter - a boolean named manualCleanup which defaults to true preserving backwards compatibility. When that value is set to false the text track will be removed from the video element whenever a source change occurs.

A new instance property named autoRemoteTextTracks_ is added to Tech that keeps track of which TextTracks have automatic life-cycle management.

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
  • Reviewed by Two Core Contributors

if (!sh) {
// Fall back to a native source hander when unsupported sources are
// deliberately set
if (_Tech.nativeSourceHandler) {
sh = _Tech.nativeSourceHandler;
} else {
log.error('No source hander found for the current source.');
return;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of this return and moving of lines 843-844 to above this conditional block are to fix a tiny issue that may have never been manifest in the wild but which I discovered during a test run.

If a Tech has no nativeSourceHandler property and selectSourceHandler returned null because no matching source handlers were found, then the line later on: this.sourceHandler_ = sh.handleSource(source, this, this.options_); would throw an exception because sh would stay null.

@misteroneill
Copy link
Member

Seems reasonable to me. I agree that it feels like the expected behavior when changing sources would be to clear out remote text tracks. And backward-compatibility is a plus as that would've been my big concern here.

I wonder if we ought to do something similar with non-remote tracks? Disable them... or something. Not for this PR, but a general thought.

const htmlTrackElement = new HTMLTrackElement(track);

if (manualCleanup !== true && manualCleanup !== false) {
// deprecation warning
log.warn('Calling addRemoteTextTrack without explicitly setting the "manualCleanup" parameter to `true` is deprecated and default to `false` in future version of video.js');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am open to some nice word-smithing here. I feel like coming up with error/warnings is not my strong suit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any reason why we need to deprecate this and not just make the change? This almost seems like a bug. If we decide not to deprecate and to just make the change we can probably make this change much smaller.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because currently, you have to manually cleanup, we're wanting to change it so that by default tracks are cleaned up automatically.

@gkatsev gkatsev added this to the 5.13 milestone Nov 4, 2016
* @return {HTMLTrackElement}
* @method addRemoteTextTrack
*/
addRemoteTextTrack(options) {
addRemoteTextTrack(options, manualCleanup) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this , manualCleanup = true) here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a default option here would make it difficult to do the deprecation warning.

@@ -531,20 +548,33 @@ class Tech extends Component {
*
* @param {Object} options The object should contain values for
* kind, language, label and src (location of the WebVTT file)
* @param {Boolean} manualCleanup if set to false, the TextTrack will be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be * @param {boolean} [manualCleanup=true], since its optional and defaults to true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also you should add an @depricated tag to the bottom stating that "The manualCleanup parameter will be removed in favor of always doing automatic cleanup in the future."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const htmlTrackElement = new HTMLTrackElement(track);

if (manualCleanup !== true && manualCleanup !== false) {
// deprecation warning
log.warn('Calling addRemoteTextTrack without explicitly setting the "manualCleanup" parameter to `true` is deprecated and default to `false` in future version of video.js');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any reason why we need to deprecate this and not just make the change? This almost seems like a bug. If we decide not to deprecate and to just make the change we can probably make this change much smaller.

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Html5 tech needs to update addRemoteTextTrack as well because it overrides the method and calls super, so, the manualCleanup option gets lost.

* @return {HTMLTrackElement}
*/
addRemoteTextTrack(options = {}) {
createRemoteTextTrack(options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be private.

return;
}

addWebVttScript() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

@@ -543,6 +560,14 @@ class Tech extends Component {
return createTrackHelper(this, kind, label, language);
}

createRemoteTextTrack(options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

Copy link
Member

@misteroneill misteroneill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

jrivera added 5 commits November 9, 2016 12:10
…th emulated and native TextTracks.

* Remove the redundancy in Html5 & Tech around remote text tracks.
* Changed Tech construction to call emulateTextTracks immediately but defer the creation of the webvtt to the `ready` event, if necessary.
* Player now passes along all arguments to the underlying Tech on addRemoteTextTrack.
Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to test it but code-wise, LGTM.

Copy link
Contributor

@brandonocasey brandonocasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending doc commet/arg changes LGTM

@@ -2525,9 +2525,9 @@ class Player extends Component {
*
* @param {Object} options Options for remote text track
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be {TextTrackList[]} theArgs track to add as remote text tracks, also theArgs is a weird name, shouldn't it be tracks?

* Creates a remote text track object and returns a html track element
*
* @param {Object} options The object should contain values for
* kind, language, label and src (location of the WebVTT file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theRest needs to be added to the doc comment, and the name is a bit weird (maybe it will make more sense to me with a doc comment.)

* @deprecated The default value of the "manualCleanup" parameter will default
* to "false" in upcoming versions of Video.js
*/
addRemoteTextTrack(...theArgs) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be changed from ...theArgs

Copy link
Contributor

@brandonocasey brandonocasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gkatsev gkatsev merged commit f05a927 into master Nov 9, 2016
@gkatsev gkatsev deleted the auto-cleaup-texttracks branch November 9, 2016 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants